package com.fenqing.leetcode.code.t300_400;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author fenqing
 */
public class Topic349 extends Topic {
    /**
     * 构造器
     *
     * @param input1 输入
     */
    public Topic349(String input1, String input2) {
        super(input1, input2);
    }

    @Execute
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int i : nums1) {
            set1.add(i);
        }
        for (int i : nums2) {
            if (set1.contains(i)) {
                set2.add(i);
            }
        }
        return set2.stream().mapToInt(Integer::valueOf).toArray();
    }

    public static void main(String[] args) {
        Topic349 topic349 = new Topic349("""
                [1,2,2,1]
                """, """
                [2,2]
                """);
        int[] run = topic349.run();
        System.out.println(Arrays.toString(run));
    }

}
